/** 
  *@CopyRight(c)2009 company Co.Ltd. 
  *@All right reserved.
  *@module name: App.BaseInfoManage.GoodsManage
  *@description:
  *
  *@author: lugj
  *@version: 1.0
  *@date: 2009/06/18
  *@last date: 2009/06/18
  *@history:
    1.
    2.
  *@bugs:
    1. 
    2. 
  *
*/ 

Ext.namespace("App.BaseInfoManage");

//GoodsManage Class
//config: {id: , }
App.BaseInfoManage.GoodsManage = function(config){
	this.config = config;
	this.MODULE_ID = App.Base.Common.func.generateGlobalUniqueId(this.config, 'GOODSMGR');

	this.OpCmd = App.Base.common.param.OP_CMD_NONE;

	this.waitTreeOpLoadMask = new Ext.LoadMask(Ext.getBody(), {msg: "系统正在加载商品信息，请稍候...", removeMask: false});
	this.waitTreeOpLoadMask.show();

	//tree
	this.asyncTreeNode = new Ext.tree.AsyncTreeNode({
		id: 'GOODSIDROOTNODE' + this.MODULE_ID,
		text: '商品信息',

		icon: App.Base.common.param.SYSMODMGR_TREE_ROOTNODE_ICON_URL,
		expandIcon: App.Base.common.param.SYSMODMGR_TREE_ROOTNODE_EXPANDICON_URL,
		qtip: '商品信息'
	});
	
	this.treePanel = new Ext.tree.TreePanel({
		id: 'treePanel' + this.MODULE_ID,
		autoScroll: true,
		root: this.asyncTreeNode,
		loader: new Ext.tree.TreeLoader({
			dataUrl: App.Base.common.param.SYSMODMGR_ASYNC_TREELOADER_DATAURL,
			baseParams: {
				module: this.MODULE_ID
			}
		}),
		listeners: {
			beforeexpandnode: function(node){
				node.select();
				node.setIcon(node.attributes['expandIcon']);				
			},
			beforecollapsenode: function(node){
				node.select();
				node.setIcon(node.attributes['icon']);				
			},
			load: function(node){
				this.waitTreeOpLoadMask.hide();
			},
			scope: this
		}
	});

	this.asyncTreeNode.expand();

	/*************************/

this.asyncTreeNode.appendChild(new Ext.tree.TreeNode({text: '商品1'}));
this.asyncTreeNode.appendChild(new Ext.tree.TreeNode({text: '商品2'}));
this.asyncTreeNode.appendChild(new Ext.tree.TreeNode({text: '商品3'}));
this.asyncTreeNode.appendChild(new Ext.tree.TreeNode({text: '商品4'}));
this.asyncTreeNode.appendChild(new Ext.tree.TreeNode({text: '商品5'}));


	/*************************/

    this.store = new Ext.data.Store({
		id: 'store' + this.MODULE_ID,
        proxy: new Ext.data.HttpProxy({url: App.Base.common.param.TRADESMGR_TRADEDAY_OPERATION_DATAURL}),
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
        }, [
            {name: 'goodsId'},
            {name: 'goodsName'},
            {name: 'goodsDesc'},
            {name: 'goodsTax'}
        ])
    });
    
    this.grid = new Ext.grid.GridPanel({
		id: 'grid' + this.MODULE_ID,
    	border: false,
    	frame: true,
        stripeRows: true,
        loadMask: {msg: '系统正在加载商品数据，请稍候...'},
        autoExpandColumn: 'Friday',
        enableColumnMove: false,
		enableColumnResize: false,
		enableHdMenu: false,
        autoDestroy: true,
        //title: '商品信息',
		sm: new Ext.grid.CellSelectionModel(),
        cm: new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
            {header: '商品编码', dataIndex: 'Sat', width: 64},
            {header: '商品名称', dataIndex: 'Sun' , width: 64},
            {header: '商品描述', dataIndex: 'Mon' , width: 64},
            {header: '商品税率', dataIndex: 'tues' , width: 64}
        ]),
        store: this.store,
        //tbar: new Ext.Toolbar(['']),
		bbar: new Ext.PagingToolbar({
			id: 'pagingtbl' + this.MODULE_ID,
            pageSize: App.Base.common.param.GRID_PAGE_SIZE_10,
            store: this.store,
            displayInfo: true,
            displayMsg: '共 {2} 条',//'显示第 {0} 条到 {1} 条记录，共 {2} 条',
            emptyMsg: "没有记录",
            plugins: new Ext.ux.PageSizePlugin()
        }),

        viewConfig: {
            forceFit: true,
            enableRowBody: true,
            getRowClass: function(record, rowIndex, p, ds) {
                var cls = 'white-row';
                switch (rowIndex%2) {
                    case 1:
                        cls = 'red-row'
                        break;
                }
                return cls;
            }
        }
    });

	this.doAdd = function(){
		new App.BaseInfoManage.GoodsMgrWindow({
			title: '新增商品信息',
			iconCls: 'x-menu-personinfolist-add',
			handler: null,
			scope: this
		}).getMainPanel().show();
	};

	this.doModify = function(){
		new App.BaseInfoManage.GoodsMgrWindow({
			title: '修改商品信息',
			iconCls: 'x-menu-systemmenusmanage-modify',
			handler: null,
			scope: this
		}).getMainPanel().show();
	};

	this.doDelete = function(){

	};

    this.formPanel = new Ext.FormPanel({
		id: 'formPanel' + this.MODULE_ID,
		autoDestroy: true,
		border: false,
		tbar: new Ext.Toolbar({
			id: 'tbar' + this.MODULE_ID ,
			border: false,
			items : ['-', {
				text:'<font color="#0000E3">新增</font>',
				iconCls: 'x-menu-personinfolist-add',
				//tooltip: {title:'Tip Title', text:'This is a an example QuickTip for a toolbar item'},
				//enableToggle: true,
				handler: function(){
					this.OpCmd = App.Base.common.param.OP_CMD_ADD;
					this.doAdd();
				},
				scope: this
			}, '-', {
				text:'<font color="#0000E3">修改</font>',
				iconCls: 'x-menu-systemmenusmanage-modify',
				handler: function(){
					this.OpCmd = App.Base.common.param.OP_CMD_MODIFY;
					this.doModify();
				},
				scope: this
			}, '-', {
				text:'<font color="#0000E3">删除</font>',
				iconCls: 'x-menu-personinfolist-delete',
				handler: function(){
					this.OpCmd = App.Base.common.param.OP_CMD_DELETE;
				},
				scope: this
			}, '-'
			]
		}),

		layout: 'border',
		items: [{
			region:'west',
			title : '商品目录树',
			width : 240,
			minWidth: 220,
			autoScroll: true,
			split : true,
			collapsible : true,
			bodyStyle:'padding:5px 5px 5px 0',
			layout: 'fit',
			items: [this.treePanel]
		},{
			region:'center',
			frame: true,
			border: false,
			autoScroll: true,
			labelAlign: 'right',
			labelWidth: 128,
			bodyStyle:'padding:5px 5px 5px 0',
			layout: 'border',
			items: [{
				region:'north',
				title : '商品查询',
				height: 120,
				border: false,
				frame: false,
				autoScroll: true,
				split : true,
				collapsible : true,
				bodyStyle:'padding:15px 5px 5px 0',
				layout: 'form',			
				items :[{
					xtype: 'textfield',
					id: 'goodsId' + this.MODULE_ID,
					name: 'goodsId' + this.MODULE_ID,
					width: 146,
					fieldLabel: '<font color="#FF0000">商品编码</font>',
					maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
					regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
					regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS
				}, 
				new Ext.Panel({
					layout:'column',
					items: [{
						width: 300,
						anchor:'95%',
						layout: 'form',
						items:[{
								xtype: 'textfield',
								id: 'goodsName' + this.MODULE_ID,
								name: 'goodsName' + this.MODULE_ID,
								width: 146,
								fieldLabel: '<font color="#FF0000">商品名称</font>',
								maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
								regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
								regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS
							}
						]
					},{
						width: 120,
						items: [
							new Ext.Button({
								text: '<font color="blue">查 询</font>',
								iconCls: 'x-button-systemmanage-search',
								handler: function(){
									

								},
								scope: this
							})	
						]
					}]
				})
				]	
			},{
				region:'center',
				title : '商品信息',
				//frame: true,
				border: false,
				autoScroll: true,
				bodyStyle:'padding:5px 5px 5px 0',
				layout: 'fit',
				items: [this.grid]		
			}]
			

		}]
	});

	this.formPanel.doLayout();

	//defined methods.
    if((typeof App.BaseInfoManage.GoodsManage.SIMULATE_SHARED_METHODS_FLAG) == "undefined")
    {
        App.BaseInfoManage.GoodsManage.SIMULATE_SHARED_METHODS_FLAG = true;   

        App.BaseInfoManage.GoodsManage.prototype.getMainPanel = function(){   
            return this.formPanel;  
        };
 
        //simulating the class's constructor().
        var __ctor = function(){
            //alert('called __constructor() ok.');
        }();

    }
}